package com.example.menuvirtualclient.presenter;

import com.example.menuvirtualclient.core.*;
import com.example.menuvirtualclient.rule.UserRule;
import com.example.menuvirtualclient.view.ILoginView;


public class LoginPresenter {

	private ILoginView _view;
	private UserRule _rule;
	
	public LoginPresenter(ILoginView view){
		_view = view;
		_rule = new UserRule(view.GetContext());
	}
	
	public void Login(){
		try{
			User user = _rule.Login(_view.GetUserName(), _view.GetPassword());
			if(user == null)
				_view.SetMessage("Advertencia", "El usuario no existe");
		}
		catch(Exception ex){
			HandleException(ex);
		}
	}
	
	private void HandleException(Exception ex){
		_view.SetMessage("Error", ex.getMessage());
	}
	
	@SuppressWarnings("unused")
	private void HandleException(String message){
		_view.SetMessage("Error", message);
	}
}
